import formJs from "./regexDetail.js"; //新增弹框配置项
import publicForm from "@/components/public/el-form.vue"; //弹框form

import {

    getSampleWorkByFid, //详情
    SamplegetStationWarnByCompanyId, //获取审核流程
} from "@/api/request.js";
export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "statusNum",
        "currentRow",
    ],
    data() {
        return {
            visible: "",
            loading: false,
            title: "闭合处理",
            isLock: false,
            dialogHeight: null,

            // 基本信息
            basicFormObj: formJs.basicFormObj,
            basicFormData: {},
            // 基本信息

            // 闭合
            // activeIndex: "1",
            activeNames: ["0"],
            closeFormData: {
                fId: "", // 申请单fid //为空判断为新增
                fCompanyid: "", // 施工标段id
                fParentid: "", // 对应的超标记录fid
                fWarningcontent: "", // 预警内容
                fReason: "", // 问题原因
                fHandleway: "", // 处理方式
                fHandleresult: "", // 处理结果
                fHandledate: "",
                fHandledates: "", // 处理日期
                fHandleusername: "", // 处理人名称
                fHandlefile: "", // 附件

                fFirstcheckresult: "", // 一级审核处理结果
                fFirstcheckopinion: "", // 一级审核处理意见
                fFirstcheckusername: "", // 一级审核处理人name
                fFirstcheckdates: "", // 一级审核处理日期
                fFirstcheckfile: "", // 一级审核附件

                fSecondcheckresult: "", // 二级审核处理结果
                fSecondcheckopinion: "", // 二级审核处理意见
                fSecondcheckusername: "", // 二级审核处理人name
                fSecondcheckdates: "", // 二级审核处理日期
                fSecondcheckfile: "", // 二级审核附件
            },
            // 闭合申请单
            handNum: false, //闭合申请单
            closeFormObj: formJs.closeFormObj, //闭合
            closeFileurllist: [], //附件

            // 闭合申请单
            //  一级审核
            firstNum: false, //一级审核
            FauditFormObj: formJs.Faudit, //一级审核
            FauditFileurllist: [], //附件
            //  一级审核

            //  二级审核
            secondNum: false, //二级审核
            SauditFormObj: formJs.Saudit, //二级审核
            SauditFileurllist: [],
            //  二级审核
            btnShow: true,
            // 闭合
            newRow: null,


        };
    },
    components: {
        publicForm,
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },

        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },

        statusNum: {
            handler(newVal) {
                if (newVal) {

                    this.edit(newVal);
                }
            },
            immediate: true,
        },

        currentRow: {
            handler(newVal) {
                this.newRow = newVal;
            },
            deep: true,
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {

        this.btnShow = true;

        // this.getData = {
        //     fId: window.location.href.split("=")[1].split("&")[0], // 超标记录fid
        //     fCompanyid: window.location.href.split("=")[2], // 选中的施工标段id
        //     //   fCompanyid: "a4b6f9f2-ad46-494f-a43c-a1cb2f8e6813",
        //     //   fId: "38442da6-ba0a-49b1-8227-bb3d63c6d309",
        //   };
        var data = {
            fId: window.location.href.split("=")[1].split("&")[0],
            fCheckstatus: window.location.href.split("=")[3],
            fCompanyid: window.location.href.split("=")[2]
        }
        console.log('data',data);
        // var data = {
        //     fId: '136cdee2-0b78-48a2-bd07-d7f0caf0093f',
        //     fCheckstatus: "1",
        //     fCompanyid: "4daf8605-cf78-425d-8b01-bffbe1db15be"
        // }
        // 
        this.getDetail(data);
        // if (this.statusNum == 7) { //查看
        this.btnShow = false
        this.handNum = true; //闭合申请单
        this.firstNum = true; //一级审核
        this.secondNum = true; //二级审核
        // 闭合
        this.closeFormObj.map((item) => {
            item.disabled = true;
        });
        // 闭合
        // 一级审核
        this.FauditFormObj.map((item) => {
            item.disabled = true;
        });
        // 一级审核
        //  二级闭合
        this.SauditFormObj.map((item) => {
            item.disabled = true;
        });
        this.closeFormObj[3].uploadSelect = false
        this.FauditFormObj[4].uploadSelect = false
        this.SauditFormObj[4].uploadSelect = false
        //  二级闭合
        // }
        this.getHeight();
    },
    methods: {
        // 折叠面板
        changeCollapse(e) {
            console.log(this.activeNames, e);
        },
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        closeDialog() {
            this.$emit("close");
        },
        selectChange(data, a, b) {
            console.log("selectChange", data, a, b);
        },

        edit() {
            this.closeFormData = this.$options.data.call(this).closeFormData;
        },

        // 详情
        getDetail(row) {
            this.loading = true;
            getSampleWorkByFid({
                fId: row.fId
            }).then((res) => {
                if (res.errcode == 0) {
                    this.loading = false;
                    this.recordfiles = [];
                    this.basicFormData = res.data.lrCheckSample; //基本信息
                    this.closeFormData = res.data.checkSampletestclose; //闭合 

                    this.closeFileurllist = res.data.fCloseSourcefileList; //闭合申请单材料List
                    this.FauditFileurllist = res.data.fFirstSourcefileList; //一级审核材料List
                    this.SauditFileurllist = res.data.fSecondSourcefileList; //二级审核材料List

                    this.getExamine(row)
                } else {
                    this.$message.error("列表数据获取失败", res.msg);
                    this.loading = false;
                }

            });
        },
        getExamine(data) {
            console.log(data, data.fCheckstatus);
            var status = data.fCheckstatus;
            SamplegetStationWarnByCompanyId({
                    fCompanyid: data.fCompanyid.substring(0, data.fCompanyid.length - 13)
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        console.log(44444444444);
                     
                            this.btnShow = false
                            // 闭合
                            this.closeFormObj.map((item) => {
                                item.disabled = true;
                            });
                            // 闭合
                            // 一级审核
                            this.FauditFormObj.map((item) => {
                                item.disabled = true;
                            });
                            // 一级审核
                            //  二级闭合
                            this.SauditFormObj.map((item) => {
                                item.disabled = true;
                            });
                            //  二级闭合
           
                            this.closeFormObj[4].uploadSelect = false
                            this.FauditFormObj[4].uploadSelect = false
                            this.SauditFormObj[4].uploadSelect = false

                            if (status == 0) {
                                this.handNum = true; //闭合申请单
                                this.firstNum = false; //一级审核
                                this.secondNum = false; //二级审核
                            } else if (status == 1) {
                                this.activeNames = ["0"];
                                this.handNum = true; //闭合申请单
                                this.firstNum = false; //一级审核
                                this.secondNum = false; //二级审核

                            } else if (status == 2) {
                                this.activeNames = ["0", "1"]
                                this.handNum = true; //闭合申请单
                                this.firstNum = true; //一级审核
                                this.secondNum = false; //二级审核

                            } else if (status == 3) {
                                this.activeNames = ["0", "1", "2"]
                                this.handNum = true; //闭合申请单
                                this.firstNum = true; //一级审核
                                this.secondNum = true; //二级审核

                            }
                        // }
                    }
                })
                .catch((error) => {
                    console.log(error);
                });
        },
        // 刪除文件
        delteFile(file, status) {
            // var obj;
            var arr;
            if (status == 0) {
                // obj = this.closeFormData;
                arr = this.closeFileurllist;
            } else if (status == 1) {
                // obj = this.FauditFormData;
                arr = this.FauditFileurllist;
            } else if (status == 2) {
                // obj = this.SauditFormData;
                arr = this.SauditFileurllist;
            }
            for (let index = 0; index < arr.length; index++) {
                if (file.uid == arr[index].uid) {
                    if (arr[index].atta == undefined) {
                        // obj.recordfiles.push({
                        this.recordfiles.push({
                            fId: arr[index].fId,
                        });
                    } else {
                        this.recordfiles.push({
                            // obj.recordfiles.push({
                            fId: arr[index].atta.fId,
                        });
                    }
                    this.closeFileurllist.splice(index, 1);
                }
            }
        },


        
  
        
    },
};